package com.ruoyi.discuss.service.impl;

import java.util.List;

import com.ruoyi.discuss.domain.Biglike;
import com.ruoyi.discuss.service.IBiglikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.discuss.mapper.BigtopicMapper;
import com.ruoyi.discuss.domain.Bigtopic;
import com.ruoyi.discuss.service.IBigtopicService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 话题Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-14
 */
@Service
public class BigtopicServiceImpl implements IBigtopicService
{
    @Autowired
    private BigtopicMapper bigtopicMapper;


    @Autowired
    private IBiglikeService biglikeService;

    /**
     * 查询话题
     *
     * @param topicid 话题主键
     * @return 话题
     */
    @Override
    public Bigtopic selectBigtopicByTopicid(Long topicid)
    {
        return bigtopicMapper.selectBigtopicByTopicid(topicid);
    }

    /**
     * 查询话题列表
     *
     * @param bigtopic 话题
     * @return 话题
     */
    @Override
    public List<Bigtopic> selectBigtopicList(Bigtopic bigtopic)
    {
        return bigtopicMapper.selectBigtopicList(bigtopic);
    }

    /**
     * 新增话题
     *
     * @param bigtopic 话题
     * @return 结果
     */
    @Override
    public int insertBigtopic(Bigtopic bigtopic)
    {
        return bigtopicMapper.insertBigtopic(bigtopic);
    }

    /**
     * 修改话题
     *
     * @param bigtopic 话题
     * @return 结果
     */
    @Override
    public int updateBigtopic(Bigtopic bigtopic)
    {
        return bigtopicMapper.updateBigtopic(bigtopic);
    }

    /**
     * 批量删除话题
     *
     * @param topicids 需要删除的话题主键
     * @return 结果
     */
    @Override
    public int deleteBigtopicByTopicids(Long[] topicids)
    {
        return bigtopicMapper.deleteBigtopicByTopicids(topicids);
    }

    /**
     * 删除话题信息
     *
     * @param topicid 话题主键
     * @return 结果
     */
    @Override
    public int deleteBigtopicByTopicid(Long topicid)
    {
        return bigtopicMapper.deleteBigtopicByTopicid(topicid);
    }

    @Transactional
    @Override
    public int addPoint(Bigtopic bigtopic) {
        Biglike biglike = new Biglike();
        biglike.setTopicid(bigtopic.getTopicid());
        biglikeService.insertBiglike(biglike);

        bigtopic.setLikescount(bigtopic.getLikescount()+1);

        return this.updateBigtopic(bigtopic);
    }
}
